package org.rency.ues.scheduler.task;

import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;

import javax.annotation.Resource;

import org.rency.common.trigger.factory.DataDaemonTemplate;
import org.rency.common.trigger.schedule.DaemonContext;
import org.rency.ues.dal.entity.EncryptDataDO;
import org.rency.ues.dal.repository.EncryptDataRepository;
import org.rency.ues.domainservice.support.EncryptData;
import org.rency.ues.domainservice.support.UesConverter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 清理过期加密数据
 * @author: user_rcy@163.com
 * </br>Created on 2016年5月4日
 * @version: V1.0.0
 * @since JDK 1.8
 */
public class ClearExpireDateJob extends DataDaemonTemplate<EncryptData,Boolean>{

	private Logger                              logger = getLogger();
		
	@Resource(name="encryptDataRepository")
	private EncryptDataRepository      encryptDataRepository;

	@Override
	public List<EncryptData> loadData(AtomicInteger pageNo) {
		List<EncryptDataDO> entityList = encryptDataRepository.getWaitExpireDate(this.getBatchSize(), pageNo.get());
		return UesConverter.convert(entityList);
	}

	@Override
	public String getKey(EncryptData domain) {
		return domain.getId()+"";
	}

	@Override
	public Boolean process(EncryptData domain) {
		logger.info("执行[{}]任务, 清除对象 : [{}].",this.getTaskName(),domain);
		return encryptDataRepository.deleteWithRela(domain.getTicket());
	}

	@Override
	public void exception(DaemonContext context, Throwable e) {
		
	}

	@Override
	public Logger getLogger() {
		return LoggerFactory.getLogger(ClearExpireDateJob.class);
	}
	
}